package org.pentaho.actioneditor.client.processpanels;

import com.google.gwt.user.client.ui.*;
import org.pentaho.actioneditor.client.messages.Messages;
import com.google.gwt.user.client.Command;


public class OutputUI {

  private FlexTable root = new FlexTable();
  private Label nameLabel = new Label();
  private Label outputTypeLabel = new Label();
  public static interface ItemCommand {
    public void execute(String text);
  }  public static interface CommandHelper {
    public Command getCommand(MenuItem item);
  }
  ItemCommand addDestinationCommand;
  CommandHelper addDestinationCommandHelper;
  private MenuItem deleteDestination = new MenuItem(Messages.getUIInstance().outputui_X(), (Command)null);
  private ScrollPanel tableScroller = new ScrollPanel();


  public void init() {
    Label obj113 = new Label(Messages.getUIInstance().outputui_Name());
    obj113.setWordWrap(false);
    root.setWidget(0,0,obj113);
    root.setWidget(0,1,nameLabel);
    root.getColumnFormatter().setWidth(1, "100%");
    Label obj114 = new Label(Messages.getUIInstance().outputui_TypeOfOutput());
    obj114.setWordWrap(false);
    root.setWidget(1,0,obj114);
    root.setWidget(1,1,outputTypeLabel);
    root.getColumnFormatter().setWidth(1, "100%");
    Label obj115 = new Label(Messages.getUIInstance().outputui_OutputDestination());
    root.setWidget(2,0,obj115);
    root.getFlexCellFormatter().setColSpan(2,0,2);
    MenuBar obj116 = new MenuBar();
    MenuItem obj117 = new MenuItem(Messages.getUIInstance().outputui_Add(), (Command)null);
    MenuBar obj118 = new MenuBar(true);
    MenuItem obj119 = new MenuItem(Messages.getUIInstance().outputui_Runtime(), (Command)null);
    obj118.addItem(obj119);
    obj119.setCommand(addDestinationCommandHelper.getCommand(obj119));
    MenuItem obj120 = new MenuItem(Messages.getUIInstance().outputui_Session(), (Command)null);
    obj118.addItem(obj120);
    obj120.setCommand(addDestinationCommandHelper.getCommand(obj120));
    MenuItem obj121 = new MenuItem(Messages.getUIInstance().outputui_Response(), (Command)null);
    obj118.addItem(obj121);
    obj121.setCommand(addDestinationCommandHelper.getCommand(obj121));
    MenuItem obj122 = new MenuItem(Messages.getUIInstance().outputui_Global(), (Command)null);
    obj118.addItem(obj122);
    obj122.setCommand(addDestinationCommandHelper.getCommand(obj122));
    MenuItem obj123 = new MenuItem(Messages.getUIInstance().outputui_File(), (Command)null);
    obj118.addItem(obj123);
    obj123.setCommand(addDestinationCommandHelper.getCommand(obj123));
    MenuItem obj124 = new MenuItem(Messages.getUIInstance().outputui_Vfsftp(), (Command)null);
    obj118.addItem(obj124);
    obj124.setCommand(addDestinationCommandHelper.getCommand(obj124));
    obj117.setSubMenu(obj118);
    obj116.addItem(obj117);
    obj116.addItem(deleteDestination);
    root.setWidget(3,0,obj116);
    root.getFlexCellFormatter().setColSpan(3,0,2);
    root.getFlexCellFormatter().setHorizontalAlignment(3,0,HasHorizontalAlignment.ALIGN_RIGHT);
    tableScroller.setWidth("100%");
    tableScroller.setHeight("100px");
    tableScroller.setAlwaysShowScrollBars(true);
    root.setWidget(4,0,tableScroller);
    root.getFlexCellFormatter().setColSpan(4,0,2);

  }

  public FlexTable getRoot() {
    return root;
  }
  public Label getNameLabel() {
    return nameLabel;
  }
  public Label getOutputTypeLabel() {
    return outputTypeLabel;
  }
  public void setAddDestinationCommand(ItemCommand itemCommand) {
    this.addDestinationCommand = itemCommand;
    addDestinationCommandHelper = new CommandHelper() {
      public Command getCommand(final MenuItem item) {
        Command cmd = new Command() {
          public void execute() {
            addDestinationCommand.execute(item.getText());
          }
        };
        return cmd;
      }
    };
  }
  public MenuItem getDeleteDestination() {
    return deleteDestination;
  }
  public ScrollPanel getTableScroller() {
    return tableScroller;
  }

}
